package com.changcheng.project.baiinfo.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.changcheng.framework.aspectj.lang.annotation.Log;
import com.changcheng.framework.aspectj.lang.enums.BusinessType;
import com.changcheng.project.baiinfo.domain.VersionInfo;
import com.changcheng.project.baiinfo.service.IVersionInfoService;
import com.changcheng.framework.web.controller.BaseController;
import com.changcheng.framework.web.domain.AjaxResult;
import com.changcheng.common.utils.poi.ExcelUtil;
import com.changcheng.framework.web.page.TableDataInfo;

/**
 * 固件白名单Controller
 * 
 * @author dazhi
 * @date 2021-03-10
 */
@Controller
@RequestMapping("/baiinfo/baiinfo")
public class VersionInfoController extends BaseController
{
    private String prefix = "baiinfo/baiinfo";

    @Autowired
    private IVersionInfoService versionInfoService;

    @RequiresPermissions("baiinfo:baiinfo:view")
    @GetMapping()
    public String baiinfo()
    {
        return prefix + "/baiinfo";
    }

    /**
     * 查询固件白名单列表
     */
    @RequiresPermissions("baiinfo:baiinfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VersionInfo versionInfo)
    {
        startPage();
        List<VersionInfo> list = versionInfoService.selectVersionInfoList(versionInfo);
        return getDataTable(list);
    }

    /**
     * 导出固件白名单列表
     */
    @RequiresPermissions("baiinfo:baiinfo:export")
    @Log(title = "固件白名单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VersionInfo versionInfo)
    {
        List<VersionInfo> list = versionInfoService.selectVersionInfoList(versionInfo);
        ExcelUtil<VersionInfo> util = new ExcelUtil<VersionInfo>(VersionInfo.class);
        return util.exportExcel(list, "baiinfo");
    }

    /**
     * 新增固件白名单
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存固件白名单
     */
    @RequiresPermissions("baiinfo:baiinfo:add")
    @Log(title = "固件白名单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VersionInfo versionInfo)
    {
        return toAjax(versionInfoService.insertVersionInfo(versionInfo));
    }

    /**
     * 修改固件白名单
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        VersionInfo versionInfo = versionInfoService.selectVersionInfoById(id);
        mmap.put("versionInfo", versionInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存固件白名单
     */
    @RequiresPermissions("baiinfo:baiinfo:edit")
    @Log(title = "固件白名单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VersionInfo versionInfo)
    {
        return toAjax(versionInfoService.updateVersionInfo(versionInfo));
    }

    /**
     * 删除固件白名单
     */
    @RequiresPermissions("baiinfo:baiinfo:remove")
    @Log(title = "固件白名单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(versionInfoService.deleteVersionInfoByIds(ids));
    }
}
